package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.StockListVo;
import com.ruoyi.system.domain.bo.StockListBo;
import com.ruoyi.system.service.IStockListService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-03-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/list")
public class StockListController extends BaseController {

    private final IStockListService iStockListService;

    /**
     * 查询【请填写功能名称】列表
     */
    @SaCheckPermission("system:list:list")
    @GetMapping("/list")
    public TableDataInfo<StockListVo> list(@Validated(QueryGroup.class) StockListBo bo, PageQuery pageQuery) {
        return iStockListService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @SaCheckPermission("system:list:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated StockListBo bo, HttpServletResponse response) {
        List<StockListVo> list = iStockListService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", StockListVo.class, response);
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @SaCheckPermission("system:list:query")
    @GetMapping("/{queryStockCode}")
    public R<StockListVo> getInfo(
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("queryStockCode") String queryStockCode) {
        return R.ok(iStockListService.queryById(queryStockCode));
    }

    /**
     * 新增【请填写功能名称】
     */
    @SaCheckPermission("system:list:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StockListBo bo) {
        return toAjax(iStockListService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @SaCheckPermission("system:list:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StockListBo bo) {
        return toAjax(iStockListService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @SaCheckPermission("system:list:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{queryStockCodes}")
    public R<Void> remove(
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] queryStockCodes) {
        return toAjax(iStockListService.deleteWithValidByIds(Arrays.asList(queryStockCodes), true) ? 1 : 0);
    }
}
